package com.skyd.core.android.game.crosswisewar;

import android.graphics.Canvas;
import android.graphics.Rect;

import com.skyd.core.android.game.GameObject;
import com.skyd.core.android.game.GameScene;
import com.skyd.core.android.game.GameSpirit;
import com.skyd.core.android.game.ICurrentFrameNumberSupport;
import com.skyd.core.game.crosswisewar.IBuff;
import com.skyd.core.game.crosswisewar.ICooling;
import com.skyd.core.game.crosswisewar.IEntity;
import com.skyd.core.game.crosswisewar.INation;
import com.skyd.core.game.crosswisewar.IScene;
import com.skyd.core.game.crosswisewar.IWarrior;
import com.skyd.core.vector.Vector2DF;

public abstract class Buff extends Warrior implements IBuff {
	
//	public Buff(){
//		_CreateTime=getCurrentFrameNumber();
//	}
	
	/**
 * 初始值为0。
 * 功能注释：效果创建时间
 */
	private  long _CreateTime = Long.MAX_VALUE;
/**
 * 获取CreateTime。
 * 功能注释：效果创建时间
 * @return 当前的long类型的值
 */
	public  long getCreateTime() {
		return _CreateTime;
	}

	/**
 * 初始值为0。
 * 功能注释：持续时间
 */
	private  int _KeepTime = 0;
/**
 * 获取KeepTime。
 * 功能注释：持续时间
 * @return 当前的int类型的值
 */
	public  int getKeepTime() {
		return _KeepTime;
	}
/**
 * 设置KeepTime。
 * 功能注释：持续时间
 * @param value 要设置的int类型值
 */
	public  void setKeepTime(int value) {
		_KeepTime = value;
	}	
/**
 * 设置KeepTime为其默认值(0)。
 * 功能注释：持续时间
 */
	public  void setKeepTimeToDefault() {
		setKeepTime(0);
	}

	@Override
	public void remove() {
		IEntity buff = getBuff();
		getBuffTarget().setBuff(buff);
		if(buff!=null)buff.setBuffTarget(getBuffTarget());
		
//		setBuffTarget(null);
		setKeepTime(-1);
		((Scene)getParentScene()).getSpiritList().remove(this);
	}

	@Override
	public void setToTarget(IWarrior value) {		
		this.setBuffTarget(value.getBuffed());
		((GameScene)value.getBuffed().getParentScene()).getSpiritList().add(this);
		this.setLevelAbove((GameSpirit) value.getBuffed());
		value.getBuffed().setBuff(this);
		_CreateTime=getCurrentFrameNumber();
	}

	@Override
	public boolean getIsCanMoveAttack() {
		return ((Warrior)getBuffTarget()).getIsCanMoveAttack();
	}

	@Override
	public int getNeedPay() {
		return ((Warrior)getBuffTarget()).getNeedPay();
	}
	@Override
	protected void updateSelf() {
//		super.updateSelf();
		if(getKeepTime()>0&&getCurrentFrameNumber()-getCreateTime()>=getKeepTime())remove();
	}
	@Override
	public GameObject getParent() {
		return (GameObject) getBuffTarget();
	}
	@Override
	public ICooling getCooling() {
		return ((Warrior)getBuffTarget()).getCooling();
	}
	@Override
	public int getSpeed() {
		return ((Warrior)getBuffTarget()).getSpeed();
	}
	@Override
	public boolean move() {
		return ((Warrior)getBuffTarget()).move();
	}
	@Override
	public void setSpeed(int value) {
		((Warrior)getBuffTarget()).setSpeed(value);
	}	
	@Override
	public boolean addOnDestroyedListener(OnDestroyedListener listener) {
		return ((Warrior)getBuffTarget()).addOnDestroyedListener(listener);
	}
	@Override
	public void attack(IEntity[] target) {
		((Warrior)getBuffTarget()).attack(target);
	}
	@Override
	public boolean checkIsInAttackDelay() {
		return ((Warrior)getBuffTarget()).checkIsInAttackDelay();
	}
	@Override
	public void clearOnDestroyedListeners() {
		((Warrior)getBuffTarget()).clearOnDestroyedListeners();
	}
	@Override
	public int getATK() {
		return ((Warrior)getBuffTarget()).getATK();
	}
	@Override
	public int getAttackDelay() {
		return ((Warrior)getBuffTarget()).getAttackDelay();
	}
	@Override
	public int getAttackRange() {
		return ((Warrior)getBuffTarget()).getAttackRange();
	}
	@Override
	public int getDEF() {
		return ((Warrior)getBuffTarget()).getDEF();
	}
	@Override
	public IEntity[] getEncounterEntity() {
		return ((Warrior)getBuffTarget()).getEncounterEntity();
	}
	@Override
	public int getHP() {
		return ((Warrior)getBuffTarget()).getHP();
	}
	@Override
	public int getMaxHP() {
		return ((Warrior)getBuffTarget()).getMaxHP();
	}
	@Override
	public int getOccupyHeight() {
		return ((Warrior)getBuffTarget()).getOccupyHeight();
	}
	@Override
	public int getOccupyWidth() {
		return ((Warrior)getBuffTarget()).getOccupyWidth();
	}
	@Override
	public boolean removeOnDestroyedListener(OnDestroyedListener listener) {
		return ((Warrior)getBuffTarget()).removeOnDestroyedListener(listener);
	}
	@Override
	public void setATK(int value) {
		((Warrior)getBuffTarget()).setATK(value);
	}
	@Override
	public void setATKToDefault() {
		((Warrior)getBuffTarget()).setATKToDefault();
	}
	@Override
	public void setAttackDelay(int value) {
		((Warrior)getBuffTarget()).setAttackDelay(value);
	}
	@Override
	public void setAttackRange(int value) {
		((Warrior)getBuffTarget()).setAttackRange(value);
	}
	@Override
	public void setDEF(int value) {
		((Warrior)getBuffTarget()).setDEF(value);
	}
	@Override
	public void setHP(int value) {
		((Warrior)getBuffTarget()).setHP(value);
	}
	@Override
	public void setMaxHP(int value) {
		((Warrior)getBuffTarget()).setMaxHP(value);
	}
	@Override
	public void setOccupyHeight(int value) {
		((Warrior)getBuffTarget()).setOccupyHeight(value);
	}
	@Override
	public void setOccupyWidth(int value) {
		((Warrior)getBuffTarget()).setOccupyWidth(value);
	}
	@Override
	public INation getNation() {
		return ((Warrior)getBuffTarget()).getNation();
	}
	@Override
	public IScene getParentScene() {
		return getBuffTarget()==null?null:((Warrior)getBuffTarget()).getParentScene();
	}
	@Override
	public Vector2DF getPositionInScene() {
		return ((Warrior)getBuffTarget()).getPositionInScene();
	}
	@Override
	public void removeFromScene() {
		
		((Warrior)getBuffTarget()).removeFromScene();
	}
	@Override
	public void setNation(INation value) {
		
		((Warrior)getBuffTarget()).setNation(value);
	}
	@Override
	public void setParentScene(IScene value) {
		if(getBuffTarget()==null)return;
		((Warrior)getBuffTarget()).setParentScene(value);
	}
	@Override
	public void setPositionInScene(Vector2DF value) {
		
		((Warrior)getBuffTarget()).setPositionInScene(value);
	}
	
	@Override
	public Vector2DF getPosition() {
		return ((Warrior)getBuffTarget()).getPosition();
	}
	
	@Override
	public void setPosition(Vector2DF value) {
		((Warrior)getBuffTarget()).setPosition(value);
	}
	
	@Override
	public void draw(Canvas c, Rect drawArea) {
		
	}
	
	@Override
	public long getCurrentFrameNumber() {
		if (getParentScene() == null)
			return -1;
		return ((ICurrentFrameNumberSupport) getParentScene())
				.getCurrentFrameNumber();
	}
}
